﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace _0812045
{
    public class Map : VisibleGameEntity
    {
        ScrollingMap scm1;
        ScrollingMap scm2;
        ScrollingMap scm3;
        public override bool Init(ContentManager content,int n, string strResource)
        {
            // Khoi tao nhan vat
            _sprite = new PictureSprite[1];
            Texture2D[] texture2D;
            texture2D = new Texture2D[1];
            texture2D[0] = content.Load<Texture2D>(@"Levels/" + strResource + "/background");
            _sprite[0] = new PictureSprite(texture2D);

            scm1 = new ScrollingMap();
            scm1.y = 180;
            scm1.Init(content,strResource,"after1");
            scm1.nDelay = 3;
            scm2 = new ScrollingMap();
            scm2.y = 180;
            scm2.Init(content,strResource,"after2");
            scm2.nDelay = 2;
            scm3 = new ScrollingMap();
            scm3.y = 420;
            scm3.Init(content,strResource,"road");
            scm3.nDelay = 1;

            return true;
        }

        public override void Update(GameTime gameTime)
        {
            scm1.Update(gameTime);
            scm2.Update(gameTime);
            scm3.Update(gameTime);
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            ((PictureSprite)_sprite[0]).Draw(gameTime, spriteBatch, new Vector2(0,0));
            scm1.Draw(gameTime, spriteBatch);
            scm2.Draw(gameTime, spriteBatch);
            scm3.Draw(gameTime, spriteBatch);
        }
        public override VisibleGameEntity Clone()
        {

            VisibleGameEntity newObject = new Map();
            //Copy các thuộc tính từ this => newObject 
            newObject._sprite = new PictureSprite[1];
            newObject._sprite[0] = new PictureSprite(this._sprite[0].texture2d);
            newObject.x = this.x;
            newObject.y = this.y;
            ((Map)newObject).scm1 = this.scm1;
            ((Map)newObject).scm2 = this.scm2;
            ((Map)newObject).scm3 = this.scm3;

            return newObject;
        }
    }
}
